#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

void swap(void* p1, void* p2, int size) {
	for (int i = 0; i < size; i++) {
		char tmp = *((char*)p1 + i);
		*((char*)p1 + i) = *((char*)p2 + i);
		*((char*)p2 + i) = tmp;
	}

}

void Bubblesort(void* base, int count, int size, int(*cmp)(void*, void*)) {
	int i = 0,j=0;
	for (i = 0; i < count - 1; i++) {
		for (j = 0; j < count - i - 1; j++) {
			if (cmp((char*)base + j * size, (char*)base + (j + 1) * size) > 0) {
				swap((char*)base + j * size, (char*)base + (j + 1) * size, size);
			}
	     }
	}
}

int int_compare(const void* p1, const void* p2) {
	return (*(int*)p1 - *(int*)p2);
}

int main() {
	int arr[] = { 9,8,7,6,5,4,3,2,1 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	Bubblesort(arr, sz, sizeof(arr[0]), int_compare);
	for (int i = 0; i < sz; i++) {
		printf("%d ", arr[i]);
	}
}